
<html>
	<head>
		<title>Test case for List</title>
		<link href="css/test.css" rel="stylesheet" type="text/css" />
		<link href="css/layout.css" rel="stylesheet" type="text/css" />

		<script src="../src/js/base/g.js" ></script>
		<script src="../src/js/utils/list.js" ></script>
		<script src="../src/js/test/test.js"></script>
		<script>
			TestCase_G_List = function(title, init, run, expect) {
				this.title = title;

				this.expect = expect;
				this.init = init || function(){};
				this.run = run || function(){};
			}

			function test_init() {
				var T= new G.Test.TestSuit("TEST SUIT FOR LIST", "center"); 

				var list_dump = function(list) {
					var str = "";
					for (var n = list.head; n != null; n = n.next) {
						str += n.data;
					}
					str += ",";
					for (var n = list.tail; n != null; n = n.prev) {
						str += n.data;
					}
					return str;
				}


				var list_test_append = function() {
					var list = new G.Utils.List();
					for (var i = 0; i < 10; i++) {
						var n = new G.Utils.ListNode(i);
						list.append(n);
					}
					var str = list_dump(list);
					this.assert_equ(str,"0123456789,9876543210");
					return list;
				}

				var list_test_insert = function() {
					var list = new G.Utils.List();
					for (var i = 0; i < 10; i++) {
						var n = new G.Utils.ListNode(i);
						list.insert(n);
					}
					var str = list_dump(list);
					this.assert_equ(str, "9876543210,0123456789");
					return list;
				}

				var list_test_remove_head = function() {
					var str = "";
					var list = new G.Utils.List();
					for (var i = 0; i < 4; i++) {
						list.append(new G.Utils.ListNode(i));
					}

					for (var i = 0; i < 4; i++) {
						list.remove(list.head);
						str += "("
						str += list_dump(list);
						str += ") "
					}
					this.assert_equ(str, "(123,321) (23,32) (3,3) (,) "); 
				}

				var list_test_remove_tail = function() {
					var str = "";
					var list = new G.Utils.List();
					for (var i = 0; i < 4; i++) {
						list.append(new G.Utils.ListNode(i));
					}

					for (var i = 0; i < 4; i++) {
						list.remove(list.tail);
						str += "("
						str += list_dump(list);
						str += ") "
					}
					this.assert_equ(str, "(012,210) (01,10) (0,0) (,) "); 
				}

				T.add_case(new G.Test.TestCase('G.Utils.List.append', null, list_test_append));
				T.add_case(new G.Test.TestCase('G.Utils.List.insert', null, list_test_insert));
				T.add_case(new G.Test.TestCase('G.Utils.List.remove_head', null, list_test_remove_head));
				T.add_case(new G.Test.TestCase('G.Utils.List.remove_tail', null, list_test_remove_tail));
				T.run();
			}
		</script>
	</head>
	<body onload="test_init()">
		<table class="layout">
			<tr>
				<td id="center"> </td>
			</tr>
		</table>
	</body>
